Difference between == and === in JavaScript

Both == and === are comparison operators in JavaScript, but they differ in how they compare values.

1. == (Equality Operator)

Example:


console.log(5 == "5"); // true (type coercion occurs)
    

Output: true

2. === (Strict Equality Operator)

Example:


console.log(5 === "5"); // false (no type coercion)
    

Output: false

Summary:

Aspect == (Equality) === (Strict Equality)
Type Conversion Performs type conversion. Does not perform type conversion.
Comparison Checks only value after type coercion. Checks both value and type.
Usage Used when type conversion is acceptable. Used when strict type matching is required.